
#import "ServerController.h"

@implementation ServerController

@synthesize server;

// non foundation initiation call
//-(void)awakeFromNib {    
//    [self startService];
//}

-(void)startService {
    netService = [[NSNetService alloc] initWithDomain:@"" type:@"_bonjour_synergy_server._tcp." name:@"" port: (int)@""];
    [netService setDelegate:self];
    [netService publish];
    server = true;
    while (server != false) {
        [[NSRunLoop currentRunLoop] runMode:NSDefaultRunLoopMode beforeDate:[NSDate distantFuture]];
    }
}

-(void)stopService {
    [netService stop];
    // [netService release];
    netService = nil;
}

-(void)dealloc {
   [self stopService];
   // [super dealloc];
}

#pragma mark Net Service Delegate Methods
-(void)netService:(NSNetService *)aNetService didNotPublish:(NSDictionary *)dict {
    NSLog(@"Hooray! We Failed to publish: %@", dict);
}

// what to do if the net service published correctly
-(void) netServiceDidPublish:(NSNetService*) sender {
	NSLog(@"Hooray! We got published with name \"%@\" on port %ld", [sender name], [sender port]);
}

// what to do if the net service will published
-(void) netServiceWillPublish:(NSNetService *)sender {
    NSLog(@"Hooray! We will get published");
}

// what to do if the net service will resolve
-(void) netServiceWillResolve:(NSNetService *)sender {
    NSLog(@"Hooray! We will resolve");
}

-(void) netService:(NSNetService*) sender didNotResolve:(NSDictionary *)dict{
    NSLog(@"Hooray! We did not resolve");
}

-(void) netServiceDidResolveAddress:(NSNetService*) sender{
    NSLog(@"Hooray! We did resolve address");
}
-(void) netService:(NSNetService*) sender didUpdateTXTRecordData:(NSDictionary *)dict{
    NSLog(@"Hooray! We will update TXT Record Data");
}
-(void) netServiceDidStop:(NSNetService*) sender{
    NSLog(@"Hooray! We did stop");
}

@end
